<div class="popup_body">
    <div class="ui_table">
        <form method="post">
            <input type="hidden" name="id" value="${(entity.id)!''}">
            <#--<input type="hidden" name="agentId" value="${Session['SESSION_KEY_USER'].agentId}">-->
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                        <td width="90" align="right">运营商：</td>
                        <td>
                            <input name="agentId" class="easyui-combotree" editable="false" required="true"
                                   style="width: 184px; height: 28px;" value="${(entity.agentId)!''}"
                                   data-options="url:'${contextPath}/security/basic/agent/tree.htm?',method:'get',onSelect: function(rec){
                                   var url = '${contextPath}/security/hdw/agency/tree.htm?agentId='+rec.id;
                                   $('#agency_id_${pid}').combotree('reload', url);},
                                   onChange:function(){
                                    $('#agency_id_${pid}').combotree('clear');
                                    }
                                    "/>
                        </td>
                    <#elseif Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENCY'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value>
                        <input type="hidden" name="agentId" value="${Session['SESSION_KEY_USER'].agentId}">
                    </#if>
                </tr>
                <tr>
                    <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value>
                        <td width="90" align="right">代理商：</td>
                        <td>
                            <input name="agencyId" class="easyui-combotree" editable="false"
                                   style="width: 184px; height: 28px;" id="agency_id_${pid}" value="${(entity.agencyId)!''}"
                                   data-options="<#if Session['SESSION_KEY_USER'].agentId??&&Session['SESSION_KEY_USER'].agentId!=0>url:'${contextPath}/security/hdw/agency/tree.htm?agentId=${Session['SESSION_KEY_USER'].agentId}',</#if>method:'get'"/>
                        </td>
                    <#elseif Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENCY'].value>
                        <input type="hidden" name="agencyId" value="${Session['SESSION_KEY_USER'].agencyId}">
                    </#if>
                </tr>
                <tr>
                    <td width="90" align="right">套餐名称：</td>
                    <td><input class="text easyui-validatebox" name="priceName" value="${(entity.priceName)!''}" required="required" ></td>
                </tr>
                <tr>
                    <td width="90" align="right">套餐类型：</td>
                    <td>
                        <select class="easyui-combobox" required="true" id="price_type_${pid}" name="type" style="width:180px;height: 30px ">
                        <#list TypeEnum as s>
                            <option value="${s.getValue()}" <#if entity.type?? && entity.type == s.getValue()>selected</#if> >${s.getName()}</option>
                        </#list>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="90" align="right">换电类型：</td>
                    <td>
                        <select class="easyui-combobox" required="true" id="active_type_${pid}"  name="activeType" style="width:182px;height:28px ">
                        <#list ActiveTypeEnum as s>
                            <option value="${s.getValue()}" <#if entity.activeType?? && entity.activeType == s.getValue()>selected</#if> >${s.getName()}</option>
                        </#list>
                        </select>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
</div>
<script>
    (function() {
        var win = $('#${pid}');
        var jform = win.find('form');
        var form = jform[0];

        var snapshot = $.toJSON({
            id: '${(entity.id)!''}',
            agentId: '${(entity.agentId)!''}',
            agencyId:'${(entity.agencyId)!''}',

            type: '${(entity.type)!''}',
            activeType: '${(entity.activeType)!''}',
            priceName: "${(entity.priceName)!''}"
        });
        var ok = function() {
            if(!jform.form('validate')) {
                return false;
            }
            var success = true;

            var values = {
                id: '${(entity.id)!''}',
                <#-- 从表单获取 -->
                agentId: form.agentId.value,
                agencyId: form.agencyId.value,

                priceName: form.priceName.value,
                type: $('#price_type_${pid}').combobox('getValue'),
                activeType: $('#active_type_${pid}').combobox('getValue')

        };

            if(snapshot != $.toJSON(values)) {
                $.ajax({
                    cache: false,
                    async: false,
                    type: 'POST',
                    url: '${contextPath}/security/hdw/exchange_price/update_basic.htm',
                    dataType: 'json',
                    data: values,
                    success: function (json) {
                    <@app.json_jump/>
                        if (json.success) {
                        } else {
                            $.messager.alert('提示信息', json.message, 'info');
                            success = false;
                        }
                    }
                });
            }

            return success;
        };

        win.data('ok', ok);
    })();
</script>
